<!-- 详情 -->
<template>
  <div class="drawer-layout">
    <el-drawer
      :title="detailTitle"
      :visible.sync="drawer"
      @closed="closedinvitation"
      size="60%"
      :wrapperClosable="false"
    >
      <div class="layout" style="position: relative" v-loading="loading">
        <div class="flex-between info-box font14">
          <div class="flex infobox-left">
            <div>
              <div>商户名称：{{ merchant.mer_name }}</div>
              <div>
                商户状态：<span style="color: #0076f6;" v-if="merchant.auth_status == 1"
                  >已认证</span
                >
                <span v-else>未认证</span>
              </div>
            </div>
            <div class="marginLeft40">
              <div>联系人：{{ merchant.user_name }}</div>
              <div>联系电话：{{ merchant.user_cellphone }}</div>
            </div>
          </div>
          <div class="infobox-right">
            售后单号：{{ refund.refund_order_no }}
          </div>
        </div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="订单详情" name="first">
            <div class="margin20">
              <el-descriptions :column="2">
                <el-descriptions-item label="商品分类" label-class-name="my-label" content-class-name="description">
                  <span
                    size="mini"
                    v-for="(item, index) in selection.category_name"
                    :key="index"
                    style="margin: 0 5px"
                    >{{ item?item:'-' }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="供货商" label-class-name="my-label" content-class-name="description"
                  >{{ supplier.supplier_name }}（id：{{
                    supplier.supplier_id
                  }}）</el-descriptions-item
                >
                <el-descriptions-item label="商品名称" label-class-name="my-label" content-class-name="description">
                  <span style="font-weight: 600">{{ selection.name }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="商品规格" label-class-name="my-label" content-class-name="description">{{
                  selection.sku_name
                }}</el-descriptions-item>
                <el-descriptions-item label="商品图片" label-class-name="my-label" content-class-name="description">
                  <el-image
                    :src="selection.sku_image"
                    style="width: 50px; height: 50px; border-radius: 4px"
                  ></el-image>
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="blockquote-box">采购订单信息</div>
            <div class="margin20">
              <el-descriptions :column="2">
                <el-descriptions-item label="订单编号" label-class-name="my-label" content-class-name="description">
                  <span style="color: #409eff">{{ order.mer_order_no }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="下单时间" label-class-name="my-label" content-class-name="description">{{
                  order.created_at
                }}</el-descriptions-item>
                <el-descriptions-item label="采购数量" label-class-name="my-label" content-class-name="description">{{
                  order.product_num
                }}</el-descriptions-item>
                <el-descriptions-item label="采购价" label-class-name="my-label" content-class-name="description">{{
                  order.coupon_unit
                }}</el-descriptions-item>
                <el-descriptions-item label="实付款" label-class-name="my-label" content-class-name="description">{{
                  order.coupon_total
                }}</el-descriptions-item>
                <el-descriptions-item label="支付方式" label-class-name="my-label" content-class-name="description"
                  >提货券</el-descriptions-item
                >

                <el-descriptions-item label="支付时间" label-class-name="my-label" content-class-name="description">{{
                  order.pay_time
                }}</el-descriptions-item>
              </el-descriptions>
            </div>
          </el-tab-pane>
          <!-- <el-tab-pane label="物流信息" name="second">
            <div class="margin20">
              <el-descriptions :column="2">
                <el-descriptions-item label="商品分类">{{
                  order.sort
                }}</el-descriptions-item>
                <el-descriptions-item label="供货商"
                  >{{ order.shop }}（id：{{ order.id }}）</el-descriptions-item
                >
                <el-descriptions-item label="商品名称">
                  <span style="font-weight: 600">{{ order.name }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="商品规格">{{
                  order.rule
                }}</el-descriptions-item>
                <el-descriptions-item label="商品图片">
                  <el-image
                    :src="order.image"
                    style="width: 50px; height: 50px; border-radius: 4px"
                  ></el-image>
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="blockquote-box">物流信息</div>
            <div class="margin20">
              <el-descriptions :column="2">
                <el-descriptions-item label="快递单号">
                  <span style="color: #409eff">sf675556678666</span>
                </el-descriptions-item>
                <el-descriptions-item label="快递名称"
                  >顺丰</el-descriptions-item
                >
                <el-descriptions-item label="收货人">xxx</el-descriptions-item>
                <el-descriptions-item label="联系电话">
                  <span>{{ tel }}</span>
                  <span @click="showtel()" style="margin-left: 10px">
                    <i
                      class="el-icon-view"
                      :style="{ color: ifshowtel ? '#409EFF' : '' }"
                    ></i>
                  </span>
                </el-descriptions-item>
                <el-descriptions-item label="收货地址"
                  >北京市 朝阳区 大望路 111号</el-descriptions-item
                >
                <el-descriptions-item label="物流明细">
                  <span>点击查看</span>
                  <i class="el-icon-truck" style="margin-left: 10px"></i>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-tab-pane> -->
          <el-tab-pane label="售后信息" name="third">
            <div class="margin20">
              <el-descriptions :column="2">
                <el-descriptions-item label="商品分类" label-class-name="my-label" content-class-name="description">
                  <el-tag
                    size="mini"
                    v-for="(item, index) in selection.category_name"
                    :key="index"
                    style="margin: 0 5px"
                    >{{ item }}</el-tag
                  >
                </el-descriptions-item>
                <el-descriptions-item label="供货商" label-class-name="my-label" content-class-name="description"
                  >{{ supplier.supplier_id }}（id：{{
                    supplier.supplier_name
                  }}）</el-descriptions-item
                >
                <el-descriptions-item label="商品名称" label-class-name="my-label" content-class-name="description">
                  <span style="font-weight: 600">{{ selection.name }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="商品规格" label-class-name="my-label" content-class-name="description">{{
                  selection.sku_name
                }}</el-descriptions-item>
                <el-descriptions-item label="商品图片" label-class-name="my-label" content-class-name="description">
                  <el-image
                    :src="selection.sku_image"
                    style="width: 50px; height: 50px; border-radius: 4px"
                  ></el-image>
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="blockquote-box flex-between">
              <div>售后信息</div>
              <!-- <div>
                <el-button
                  type="text"
                  icon="el-icon-document"
                  @click="ifshow = true"
                  >售后历史</el-button
                >
              </div> -->
            </div>
            <div class="margin20">
              <el-descriptions :column="2">
                <el-descriptions-item label="申请时间" label-class-name="my-label" content-class-name="description">{{
                  refund.created_at
                }}</el-descriptions-item>
                <el-descriptions-item label="退款方式" label-class-name="my-label" content-class-name="description">
                  <span style="color: #0076f6;"
                    v-if="item.tag_value == refund.pay_type"
                    v-for="(item, index) in payTypeList"
                    :key="index"
                    >{{ item.tag_name }}</span
                  >
                </el-descriptions-item>
                <el-descriptions-item label="退货数量" label-class-name="my-label" content-class-name="description">{{
                  refund.refund_number
                }}</el-descriptions-item>
                <el-descriptions-item label="退款总额" label-class-name="my-label" content-class-name="description">{{
                  refund.coupon_total
                }}</el-descriptions-item>
                <el-descriptions-item label="售后原因" label-class-name="my-label" content-class-name="description">{{
                  refund.remark
                }}</el-descriptions-item>
                <el-descriptions-item label="申请说明" label-class-name="my-label" content-class-name="description">{{
                  refund.supplementary_info
                }}</el-descriptions-item>
              </el-descriptions>
              <!-- 根据审核状态判断是否显示审核信息和审核按钮 -->
              <el-divider></el-divider>
              <el-descriptions :column="2">
                <el-descriptions-item label="审核结果" label-class-name="my-label" content-class-name="description">
                  <el-tag size="mini" v-if="refund.status == 1">待审核</el-tag>
                  <el-tag size="mini" type="success" v-if="refund.status == 6"
                    >审核通过</el-tag
                  >
                  <el-tag size="mini" type="danger" v-if="refund.status == 9"
                    >审核未通过</el-tag
                  >
                  <el-tag size="mini" type="danger" v-if="refund.status == 10"
                    >取消申请</el-tag
                  ></el-descriptions-item
                >
                <el-descriptions-item label="审核说明" label-class-name="my-label" content-class-name="description">{{
                  refund.admin_remark
                }}</el-descriptions-item>
                <el-descriptions-item label="审核人员" label-class-name="my-label" content-class-name="description">{{
                  refund.admin_username
                }}</el-descriptions-item>
                <el-descriptions-item label="审核时间" label-class-name="my-label" content-class-name="description">{{
                  refund.audit_time
                }}</el-descriptions-item>
              </el-descriptions>
            </div>
            <div
              v-if="refund.status == 1"
              style="
                display: flex;
                justify-content: flex-end;
                margin-right: 20px;
              "
            >
              <el-button type="primary" plain @click="check(1, OrderDetail.id)"
                >审核驳回</el-button
              >
              <el-button type="primary" @click="check(2, OrderDetail.id)"
                >审核通过</el-button
              >
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
    <history v-if="ifshow"></history>
  </div>
</template>
<script>
import history from "./purchasereturnorderhistory.vue";
import { getRefundOrderDetail } from "@/api/order/index";
import { getDictionaryTypeList } from "@/api/index";
export default {
  name: "detail",
  props: ["detailTitle", "ids"],
  components: {
    history,
  },
  data() {
    return {
      loading: false,
      id: "",
      drawer: true,
      detailtitle: "",
      activeName: "first",
      merchant: {},
      order: {},
      selection: {
        category_name: [],
      },
      refund: {},
      payTypeList: [],
      tel: "188********",
      ifshowtel: false,
      sh: {
        time: "2024-01-13 12:13:13",
        way: "提货券",
        num: "10",
        price: "1000.00",
        reason: "质量问题",
        info: "因为质量问题需要平台售后",
      },
      ifshow: false,
      OrderDetail: "",
      supplier: {},
    };
  },
  mounted() {
    this.id = this.ids;
    this.loading = true;
    getDictionaryTypeList({ type: "pay_type" }).then((res) => {
      if (res.code !== 200 || res.status !== 1) {
        return this.$messages.error(res.msg);
      }
      this.payTypeList = res.data;
      this.getRefundOrderDetailWay();
    });
  },
  methods: {
    getRefundOrderDetailWay() {
      this.loading = true;
      getRefundOrderDetail({ id: this.id }).then((res) => {
        this.loading = false;
        if (res.code !== 200 || res.status !== 1) {
          this.$messages.error(res.msg);
          return;
        }
        this.OrderDetail = res.data;
        this.merchant = this.OrderDetail.merchant;
        this.order = this.OrderDetail.order;
        this.selection = this.OrderDetail.selection;
        this.supplier = this.OrderDetail.supplier;
        this.refund = this.OrderDetail.refund;
      });
    },
    // 关闭添加抽屉
    closedinvitation() {
      this.$parent.closedetail();
    },
    closedetail() {
      this.ifshow = false;
    },
    handleClick(tab, event) {
      // console.log(tab, event);
    },
    showtel() {
      this.ifshowtel = !this.ifshowtel;
      if (this.ifshowtel == true) {
        this.tel = "18888888888";
      } else {
        this.tel = "188********";
      }
    },
    check(type, id) {
      if (type == 1) {
        this.$prompt("请填写驳回原因", "审核驳回", {
          inputValidator: (value) => {
            if (!value) {
              return "请填写驳回原因";
            }
          },
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        })
          .then(({ value }) => {
            var obj = {
              id: id,
              status: 3,
              admin_remark: value ? value : "",
            };
            this.loading = true;
            auditingRefundOrderAudit(obj).then((res) => {
              if (res.code !== 200 || res.status !== 1) {
                this.loading = false;
                this.$messages.error(res.msg);
                return;
              }
              this.$messages.success(res.msg);
              this.getListWay();
            });
          })
          .catch(() => {});
      } else {
        this.$prompt("请填写通过原因", "审核通过", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        })
          .then(({ value }) => {
            var obj = {
              id: this.id,
              status: 2,
              admin_remark: value,
            };
            var obj = {
              id: id,
              status: 2,
              admin_remark: value ? value : "",
            };
            this.loading = true;
            auditingRefundOrderAudit(obj).then((res) => {
              if (res.code !== 200 || res.status !== 1) {
                this.loading = false;
                this.$messages.error(res.msg);
                return;
              }
              this.$messages.success(res.msg);
              this.getListWay();
            });
          })
          .catch(() => {});
      }
    },
  },
};
</script>
<style lang="scss">
  .my-label {
    width: 100px !important;
      font-size: 14px;
      font-weight: 550;
      line-height: 30px;
    }

    .description {
      line-height: 30px;
      font-size: 14px;
      font-weight: 550;
    }
.drawer-layout {
  /*1.显示滚动条：当内容超出容器的时候，可以拖动：*/
  .el-drawer__body {
    overflow: auto;
  }

  /*2.隐藏滚动条，太丑了*/
  .el-drawer__container ::-webkit-scrollbar {
    display: none;
  }

  .el-drawer__header {
    background-color: #0256ff;
    color: #ffffff;
    padding: 10px 20px;
    margin-bottom: 10px;
  }

  .el-tabs--card {
    height: calc(100vh - 110px);
    /* overflow-y: auto; */
  }

  .el-tab-pane {
    height: calc(100vh - 110px);
    overflow-y: auto;
  }

  .el-tabs__header {
    padding-left: 50px;
    margin: 0;
  }

  .el-tabs__item {
    padding: 0 40px;
  }

  .el-tabs__nav-wrap::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background-color: #ffffff;
    z-index: 1;
  }

  .el-alert--warning.is-light .el-alert__description {
    color: #c77b04;
    font-size: 14px;
  }

  .form-box-item {
    .el-form-item__label {
      font-size: 14px;
      font-weight: 500;
      // width: 96px;
    }

    .el-input {
      width: 250px;
    }
  }
}
</style>
<style lang="scss" scoped>
.margin20 {
  margin: 20px;
}

.flex-between {
  display: flex;
  justify-content: space-between;
}

.flex {
  display: flex;
}

.marginLeft40 {
  margin-left: 90px;
}

.font14 {
  font-size: 14px;
}

.blockquote-box {
  border-left: 4px solid #0256ff;
  padding: 0 16px;
  margin: 16px 0;
  height: 40px;
  line-height: 40px;
  background: #fafafa;
  font-size: 14px;
}

.info-box {
  color: #606266;
  font-weight: bold;
  margin: 14px 20px;
  border: 1px solid #ededed;
  padding: 10px 20px;
  border-radius: 4px;

  .infobox-left > div > div:first-child {
    margin-bottom: 20px;
  }

  .infobox-right {
    color: #606266;
  }
}
</style>
